<script setup>
import {ref, defineEmits} from 'vue';


const todoName = ref('');
const emit = defineEmits(['add']);

const handleAdd = () => {
  if (todoName.value) {
    // 添加任务
    emit('add', todoName.value);
    todoName.value = '';
  }
  else return alert("任务不能为空");
}
</script>

<template>
  <!-- 输入框 -->
  <header class="header">
    <h1>小黑记事本</h1>
    <input v-model.trim="todoName" @keyup.enter="handleAdd" placeholder="请输入任务" class="new-todo"/>
    <button @click="handleAdd" class="add">添加任务</button>
  </header>
</template>

<style scoped>

</style>